<style>
	.sc{
		background-color: red;
		color: white;
	}
	table.altrowstable {
		font-family: verdana,arial,sans-serif;
		font-size:11px;
		color:#333333;
		border-width: 1px;
		border-color: #a9c6c9;
		border-collapse: collapse;
	}
	table.altrowstable thead th {
		border-width: 1px;
		padding: 8px;
		border-style: solid;
		border-color: #a9c6c9;
	}
	table.altrowstable tbody td {
		border-width: 1px;
		padding: 8px;
		padding-left: 40px;
		padding-right: 40px;
		border-style: solid;
		border-color: #a9c6c9;
	}
</style>
	<h3>我的订单</h3>
	<div>
	<table class="altrowstable">
		<thead>
			<tr>

				<th>编号</th>
				<th>位置</th>
				<th>居室</th>
				<th>面积(/平方)</th>
				<th>时间(/月)</th>
				<th>总金额(/元)</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id="tbodyId">
			<tr>
			   <td colspan="7">数据正在加载中...</td>

			</tr>
		</tbody>
	</table>
	</div>


<script src="bower_components/jquery/dist/jquery.min.js" ></script>
<script type="text/javascript">


			$(function (){

				dowodedingdan();
			})

			function dowodedingdan(){

				let url = 'findHouseById';
				let params='user_id=2';
				$.ajax({
					url:url,
					data:params,


					success(result) {
						doFindAll(result)
						//console.log(result)


					}

				})
			}
			function doFindAll(result) {
				if (result.state == 1) {

					doSetTableBodyRows(result.data);

				} else {

					alert("程序开小差啦！！！")
				}
			}
			function doSetTableBodyRows(data){
				//console.log(data)
				let tBody=$("#tbodyId");
				tBody.empty();
				for (let i=0;i<data.length;i++){
					tBody.append(doCreateRow(data[i],i));
				}
			}

			function doCreateRow(rows,i){
				let x =rows.stopTime;
				let sdate = new Date(x);
				let time1 = sdate.getTime();
				let y =rows.beginTime;
				let bdate = new Date(y);
				let time2 = bdate.getTime();
				let ctain = Math.abs(time1-time2);
				let ztian = Math.ceil(ctain/(1000*3600*24*30));
				let pr = rows.price;
				console.log(pr);
				let zh=pr*ztian;


				return `
						<tr>
						<td>${i+1}</td>
						<td>${rows.place}</td>
						<td>${rows.room}</td>
						<td>${rows.area}</td>
						<td>${ztian}</td>
						<td>${zh}</td>
						<td><button class="sc" onclick="sc(${rows.id})">删除</button></td>
						</tr>`
			}
			function sc(id){
				let url=`dodeleteHouse/${id}`
				$.ajax({
					url:url,
					success(result) {
						alert("删除成功")
						dowodedingdan();
					}

				})
			}
</script>

